package com.chapter16.Runnable_;

/**
 * @author 宋鑫宇
 * @version 1.0
 * 通过实现接口 Runnable 来开发线程
 */
public class Runnable_ {
    public static void main(String[] args) {
        Cat cat = new Cat();
        //这离不能直接调用start方法，需要创建Thread 对象把cat放进去
        Thread thread = new Thread(cat);//这里使用了代理模式（静态代理）
        thread.start();
    }
}

class Cat implements Runnable {

    @Override
    public void run() {
        int count = 0;
        while (true) {
            System.out.println("Cat..." + (++count) + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (count == 10) {
                break;
            }
        }
    }
}

